// 购物网站核心数据类型定义

// 商品分类接口
export interface Category {
  id: string
  name: string
  icon?: string
  image?: string
  description?: string
  parentId?: string | null
  level: number
  sort: number
  children?: Category[]
}

// 商品品牌接口
export interface Brand {
  id: string
  name: string
  logo?: string
  description?: string
  sort: number
}

// 商品规格接口
export interface ProductSpec {
  name: string
  key: string
  list: ProductSpecOption[]
}

// 商品规格选项接口
export interface ProductSpecOption {
  name: string
  value: string
  image?: string
  disabled?: boolean
}

// 商品SKU接口
export interface ProductSku {
  id: string
  productId: string
  price: number
  originalPrice?: number
  stock: number
  image?: string
  specs: Record<string, string> // 规格组合，如：{ color: 'red', size: 'xl' }
  weight?: number
  volume?: number
}

// 商品基础信息接口
export interface Product {
  id: string
  name: string
  description: string
  summary?: string
  categoryId: string
  brandId?: string
  images: string[]
  defaultPrice: number
  originalPrice?: number
  sales: number
  stock: number
  status: 'active' | 'inactive' | 'out_of_stock'
  tags?: string[]
  specs?: ProductSpec[]
  skus?: ProductSku[]
  rating: number
  reviewCount: number
  weight?: number
  volume?: number
  createdAt: string
  updatedAt: string
}

// 购物车商品项接口
export interface CartItem {
  id: string
  productId: string
  skuId?: string
  product: Product
  sku?: ProductSku
  quantity: number
  selected: boolean
  addedAt: string
}

// 购物车接口
export interface Cart {
  items: CartItem[]
  totalQuantity: number
  totalPrice: number
  selectedQuantity: number
  selectedPrice: number
}

// 收货地址接口
export interface Address {
  id: string
  userId: string
  name: string
  phone: string
  province: string
  city: string
  district: string
  detail: string
  postalCode?: string
  isDefault: boolean
  createdAt: string
  updatedAt: string
}

// 用户接口
export interface User {
  id: string
  username: string
  nickname?: string
  avatar?: string
  phone?: string
  email?: string
  gender?: 'male' | 'female' | 'unknown'
  birthday?: string
  level: number
  points: number
  balance: number
  status: 'active' | 'inactive' | 'banned'
  createdAt: string
  updatedAt: string
}

// 订单状态枚举
export type OrderStatus = 
  | 'pending_payment'    // 待付款
  | 'pending_shipment'   // 待发货
  | 'shipped'            // 已发货
  | 'delivered'          // 已收货
  | 'completed'          // 已完成
  | 'cancelled'          // 已取消
  | 'refunding'          // 退款中
  | 'refunded'           // 已退款

// 订单商品项接口
export interface OrderItem {
  id: string
  orderId: string
  productId: string
  skuId?: string
  product: Product
  sku?: ProductSku
  quantity: number
  price: number
  totalPrice: number
}

// 订单接口
export interface Order {
  id: string
  orderNo: string
  userId: string
  status: OrderStatus
  items: OrderItem[]
  totalQuantity: number
  totalPrice: number
  discountAmount: number
  shippingFee: number
  finalPrice: number
  paymentMethod?: string
  paymentTime?: string
  shippingAddress: Address
  shippingTime?: string
  deliveryTime?: string
  completedTime?: string
  cancelledTime?: string
  cancelReason?: string
  remark?: string
  createdAt: string
  updatedAt: string
}

// 商品评价接口
export interface Review {
  id: string
  userId: string
  productId: string
  orderId: string
  rating: number
  content: string
  images?: string[]
  reply?: string
  isAnonymous: boolean
  createdAt: string
  updatedAt: string
  user?: Pick<User, 'id' | 'nickname' | 'avatar'>
}

// 优惠券类型枚举
export type CouponType = 'fixed' | 'percent' | 'shipping'

// 优惠券接口
export interface Coupon {
  id: string
  name: string
  type: CouponType
  value: number // 固定金额或折扣百分比
  minAmount: number // 最低消费金额
  maxDiscount?: number // 最大折扣金额（仅限percent类型）
  validFrom: string
  validTo: string
  totalCount: number
  usedCount: number
  userLimit: number // 每用户限领数量
  status: 'active' | 'inactive'
  description?: string
  createdAt: string
}

// 轮播图接口
export interface Banner {
  id: string
  title: string
  image: string
  link?: string
  linkType: 'product' | 'category' | 'url' | 'none'
  sort: number
  status: 'active' | 'inactive'
  startTime?: string
  endTime?: string
}

// 搜索历史接口
export interface SearchHistory {
  id: string
  keyword: string
  count: number
  createdAt: string
}

// 热门搜索接口
export interface HotSearch {
  id: string
  keyword: string
  sort: number
  status: 'active' | 'inactive'
}

// API响应基础接口
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
  success: boolean
}

// 分页查询参数接口
export interface PageQuery {
  page: number
  pageSize: number
  keyword?: string
  categoryId?: string
  brandId?: string
  minPrice?: number
  maxPrice?: number
  sortBy?: 'price' | 'sales' | 'rating' | 'created'
  sortOrder?: 'asc' | 'desc'
}

// 分页响应接口
export interface PageResult<T = any> {
  list: T[]
  total: number
  page: number
  pageSize: number
  hasMore: boolean
}